common={
	initCatalogueMagePage:function(){
		this.Authorization= window.localStorage.getItem("auth_token") || '';
		// 绑定dom对象
		this.obj = {
			searchText:$('#searchText'),
		};
		// 声明全局变量
		this.vars = {
			datatable:[],
			datacreat:{
				name :"",
				transcodingFlag:"",
				isEncrypt: "",
				m1:"",
				ia1:"",
				ic1:"",
				accessCode:"",
				platformCode:"",
				account:"",
				password:"",
				slaveIp:"",
				slavePort:"",
				area:"",
				affiliationUnit:"",
				affiliationLinkman:"",
				affiliationPhone:"",
				exploitUnit:"",
				supportUnit:""
			},
			searchTable:{
				platformName:"",
				platformCode:"",
				page:1,
				size:10,
			},
		};
		this.selectInputInit();
		this.sublimeform();
		this.ajaxtable();
		this.btnEvent();
	},
	selectInputInit:function() { // 地区input级联选择
		jrequest.get("/api/assessMent/selectByArea",{}).then(res => {
			var data = res.data;
			data[0].code=1;
			$.each(data[0].cityAreaVOS,function(i,dom){
				data[0].cityAreaVOS[i].code=2;
				$.each(data[0].cityAreaVOS[i].cityAreaVOS,function(j,dom){
					data[0].cityAreaVOS[i].cityAreaVOS[j].code=3;
				})
			})
			this.creatMainRido("qrm-main",data,"cityAreaVOS","code");
		})
	},
	creatMainRido:function(id,attr,child,jibie){
		$(id).html("");
		var sttrdiv="";
		for(var i=0;i<3;i++){
			sttrdiv +="<div class='qrm-border"+(i+1)+"' style='display:none'>"+
				"<ul class='qrm-lev-"+(i+1)+" qrm-lev' id='qrm-border1'>"+
				"</ul>"+
				"</div>"
		};
		$(".qrm-main").html(sttrdiv);
		var str="";
		$("#qrm-border1").html("");
		var forTree = function(o){
			for(var i=0;i<o.length;i++){
				var urlstr = "";
				try{
					urlstr = "<li><span data-id='"+o[i]["id"]+"'>"+ o[i]["name"] +"</span><i class='qrm-arrow-right'></i><ul class='li-zi-"+o[i][jibie]+"' style='display: none'>";
					str += urlstr;
					if(o[i][child] != null){
						forTree(o[i][child]);
					}
					str += "</ul>";
				}catch(e){}
			}
			return str;
		};
		$("#qrm-border1").html(forTree(attr));
	},
	sublimeform:function(){
		$.myvali({
			myform:".form2",								//表单id
			mybtn:".btn",									//提交表单按钮id
			myVali:".vali",									//input父盒子的class，可自定义类名

			Required:".Required",							//验证必填选项，值为Required,input自己加class
			RequiredTps:["不能为空!!!"],						//只验证不为空提示

			Requireds:".Requireds",							//验证必填不同提示，值为Requireds,input自己加class
			reqtps:".reqtps",								//验证不为空不同提示,input父盒子的class,可自定义类名
			ReqlengthTps:["+请输入数字"],						//验证不为空长度提示
			RequiredsTps:["请输入数字"],					    //默认提示

			myNuber:".nub",									//数字验证
			myPassword:".pasw",                             //密码验证
			myIPbox:".numip",                               //IP验证
			myareabox:".Areat"                              //地区验证
		});
	},
	tableEvent:function(id,data,columns,paginationShow,total){
		var self=this;
		$('#' + id).bootstrapTable({
			method: 'get',
			cache: false,
			height: 430,
			pagination: paginationShow,
			pageSize: self.vars.searchTable.size,
			pageNumber:self.vars.searchTable.page,
			showColumns: true,
			striped: true,
			columns: columns,
			data :data,
			sidePagination: 'server',
			totalRows: total,
			onPageChange: function (size, number) {
				console.log(size)
				console.log(number)
				self.vars.searchTable.size=size;
				self.vars.searchTable.page=number;
				self.ajaxtable()
			},
			formatNoMatches: function(){
				return '无符合条件的记录';
			}
		});
	},
	creatTable:function(res){
		var self=this;
		var columnsOne = [
			{
				field: 'id',
				title: '序号',
				align: 'center',
				formatter: function (value, row, index) {
					var pageSize=self.vars.searchTable.size;
					var pageNumber=self.vars.searchTable.page;
					return pageSize * (pageNumber - 1) + index + 1;
				}
			},
			{
				field: 'name',
				title: '平台名称',
			},
			{
				field: 'accessCode',
				title: '接入码',
			},
			{
				field: 'account',
				title: '接入用户名',
			},
			{
				field: 'masterStatus',
				title: '主链路状态',
			},
			{
				field: 'slaveStatus',
				title: '从链路状态',
			},
			{
				field: 'slaveIp',
				title: '从链路IP',
			},
			{
				field: 'slavePort',
				title: '从链路端口',
			},
			{
				field: 'createTime',
				title: '创建时间',
			},
			{
				field: 'caozuo',
				title: '操作',
				formatter: self.operateFormatter,
				events:window.operateEvents = {
					'click #ran_xq': function (e, value, row, index) {
						$("#gzDialog").show();
						self.ajaxxqingdata(row);
					},
					'click #table_edit': function (e, value, row, index) {
						$("#addbjcont").show();
						self.ajaxBianji(e, value, row, index) ;

					},
					'click #table_del': function (e, value, row, index) {
						self.ajaxDel(e, value, row, index)
					},
				},

			},
		];
		self.tableEvent("check_detail",res.data,columnsOne,true,res.total);
	},
	ajaxtable:function(){
		var self=this;
		jrequest.get(urls.infopt,self.vars.searchTable).then(res => {
			console.log("123",res)
			self.vars.datatable = res.data;
			$('#check_detail').bootstrapTable('destroy');
			self.creatTable(res)
		})
	},
	ajaxBianji: function(e, value, row, index) {
		let self = this;
		var dataCount=$.map(self.vars.datacreat,function(value,key){
			return key
		});
		jrequest.get(`/api/platforms/${row.id}`,).then(res => {
			if (res) {
				console.log(res)
				$.each(dataCount,function(i,dom){
                    if(dom=="transcodingFlag"){
                        if(res.data[dom]=="0"){
                            $("#addbjcont ul li").eq(i).find("input[type='radio']").eq(0).attr('checked','checked');
                        }else{
                            $("#addbjcont ul li").eq(i).find("input[type='radio']").eq(1).attr('checked','checked');
                        }
                    }else if(dom=="isEncrypt"){
                        if(res.data[dom]=="0"){
                            $("#addbjcont ul li").eq(i).find("input[type='radio']").eq(0).attr('checked','checked');
                            $("#addbjcont .addCit").show();
                        }else{
                            $("#addbjcont ul li").eq(i).find("input[type='radio']").eq(1).attr('checked','checked');
                            $("#addbjcont .addCit").hide();
                        }
                    }else{
                        $("#addbjcont ul li").eq(i).find("input").val(res.data[dom])
                    }
				});
			}
		});
        $("#addbjcont input[name=zmjm]").click(function(){
            var dataval = $(this).val();
            if(dataval==0){
                $("#addbjcont .addCit").show();
            }else{
                $("#addbjcont .addCit").hide();
            }
        });
		self.vars.datacreat.id=row.id;
		$("#addbjcont .primray").click(function(){
			var tablesave={};
			tablesave.id=row.id;
			$.each(dataCount,function(i,dom){
                if(dom=="transcodingFlag"){
                    if($("#addbjcont ul li").eq(i).find("input[type='radio']").eq(0).is(':checked')){
                        tablesave[dom]="0"
                    }else{
                        tablesave[dom]="1"
                    }
                }else if(dom=="isEncrypt"){
                    if($("#addbjcont ul li").eq(i).find("input[type='radio']").eq(0).is(':checked')){
                        tablesave[dom]="0"
                    }else{
                        tablesave[dom]="1"
                    }
                }else{
                    tablesave[dom]=$("#addbjcont ul li").eq(i).find("input").val()
                }
			});
			console.log(tablesave)
			if(tablesave.id) {
				tablesave.id=row.id;
				$.each(dataCount,function(i,dom){
					self.vars.datacreat[dom]=tablesave[dom]
				});
				self.addSubmit()
				return false
			}
		});
	},
	addSubmit:function(){
		let self = this;
		console.log(self.vars.datacreat)
		if (self.vars.datacreat.id){
			jrequest.put("/api/platforms",self.vars.datacreat).then(res => {
				if(res) {
					$("#addbjcont").hide();
					self.ajaxtable()
				}
			})
		}

	},
	ajaxDel: function (e, value, row, index) {
		let self = this;
		JPop.dialogDel({msg:'确定删除?',operate:true}).on(success => {
            if (success) {
                jrequest.delete(`/api/platforms/${row.id}`, {}).then(res => {
					self.ajaxtable()
				})
            }
        })
	},
	ajaxxqingdata:function(row){
		var self=this;
		var xqurl=HTTP+urls.dataxq;
		console.log(xqurl)

		$.ajax({
			headers: {
				authorization: self.Authorization
			},
			contentType: "application/json;charset=utf-8",
			dataType: "json",
			data:{
				id:"1"
			},
			url: xqurl+row.id,
			type: "get",
			success: function (data) {
				console.log("13",data)
			}
		});
		var xqurl1=HTTP+urls.dataxq1;
		$.ajax({
			headers: {
				authorization: self.Authorization
			},
			contentType: "application/json;charset=utf-8",
			dataType: "json",
			data:{
				id:"1"
			},
			url: xqurl1+row.id,
			type: "get",
			success: function (data) {
				function creatid(id){
					$(id).eq(0).find("ul.tank_ul li").eq(0).find("input").val(data.name)
					$(id).eq(0).find("ul.tank_ul li").eq(1).find("input").val(data.accessCode)
					$(id).eq(0).find("ul.tank_ul li").eq(2).find("input").val(data.account)
					$(id).eq(0).find("ul.tank_ul li").eq(3).find("input").val(data.password)
					$(id).eq(0).find("ul.tank_ul li").eq(4).find("input").val(data.slaveIp)
					$(id).eq(0).find("ul.tank_ul li").eq(5).find("input").val(data.platformType)
					$(id).eq(0).find("ul.tank_ul li").eq(6).find("input").val(data.masterStatus)
					$(id).eq(0).find("ul.tank_ul li").eq(7).find("input").val(data.affiliationUnit)
					$(id).eq(0).find("ul.tank_ul li").eq(8).find("input").val(data.affiliationLinkman)
					$(id).eq(0).find("ul.tank_ul li").eq(9).find("input").val(data.affiliationPhone)
					$(id).eq(0).find("ul.tank_ul li").eq(10).find("input").val(data.exploitUnit)
					$(id).eq(0).find("ul.tank_ul li").eq(11).find("input").val(data.supportUnit)
				}
				creatid(".tank_containner .tank_con")
			}
		});
		var xqurl2=HTTP+urls.dataxq2;
		$.ajax({
			headers: {
				authorization: self.Authorization
			},
			contentType: "application/json;charset=utf-8",
			dataType: "json",
			data:{
				id:"1"
			},
			url: xqurl2+row.id,
			type: "get",
			success: function (data) {
				console.log($(".tank_containner .tank_con").eq(1).find(".tank_contit span").text())
				function creatid(id){
					$(id).eq(1).find(".tank_contit span").text(data.lastMonth)
					$(id).eq(1).find("ul.tank_ul li").eq(0).find("input").val(data.qualifiedNum)
					$(id).eq(1).find("ul.tank_ul li").eq(1).find("input").val(data.total)
					$(id).eq(1).find("ul.tank_ul li").eq(2).find("input").val(data.qualifiedLv+"%")
				}
				creatid(".tank_containner .tank_con")

			}
		})
		var xqurl3=HTTP+urls.dataxq3;
		$.ajax({
			headers: {
				authorization: self.Authorization
			},
			contentType: "application/json;charset=utf-8",
			dataType: "json",
			data:{
				id:"1"
			},
			url: xqurl3+row.id,
			type: "get",
			success: function (data) {
				function creatid(id,num){
					$(id).eq(2).find(".tank_zs").eq(num).find("ul li").eq(0).find("span").text(data[num].total)
					$(id).eq(2).find(".tank_zs").eq(num).find("ul li").eq(1).find("span").text(data[num].onlineVehile)
					$(id).eq(2).find(".tank_zs").eq(num).find("ul li").eq(2).find("span").text(data[num].onlineVehileLv+"%")
					$(id).eq(2).find(".tank_zs").eq(num).find("ul li").eq(3).find("span").text(data[num].monthVehile)
					$(id).eq(2).find(".tank_zs").eq(num).find("ul li").eq(4).find("span").text(data[num].monthVehileLv+"%")
				}
				creatid(".tank_containner .tank_con",0)
				creatid(".tank_containner .tank_con",1)
				creatid(".tank_containner .tank_con",2)

			}
		})
		var xqurl4=HTTP+urls.dataxq4;
		$.ajax({
			headers: {
				authorization: self.Authorization
			},
			contentType: "application/json;charset=utf-8",
			dataType: "json",
			data:{
				id:"1"
			},
			url: xqurl4+row.id,
			type: "get",
			success: function (data) {
				function creatid(id){
					$(id).eq(3).find(".tank_zs").eq(0).find("ul li").eq(0).find("span").text(data.guardTotal)
					$(id).eq(3).find(".tank_zs").eq(0).find("ul li").eq(1).find("span").text(data.guardAnswer)
					$(id).eq(3).find(".tank_zs").eq(0).find("ul li").eq(2).find("span").text(data.guardLv+"%")
					$(id).eq(3).find(".tank_zs").eq(1).find("ul li").eq(0).find("span").text(data.messageTotal)
					$(id).eq(3).find(".tank_zs").eq(1).find("ul li").eq(1).find("span").text(data.messageAnswer)
					$(id).eq(3).find(".tank_zs").eq(1).find("ul li").eq(2).find("span").text(data.messageTotal+"%")
				}
				creatid(".tank_containner .tank_con")

			}
		})
		// var xqurl5=HTTP+urls.dataxq5;
		// $.ajax({
		// 	headers: {
		// 		authorization: self.Authorization
		// 	},
		// 	contentType: "application/json;charset=utf-8",
		// 	dataType: "json",
		// 	data:{
		// 		id:"1"
		// 	},
		// 	url: xqurl5+row.id,
		// 	type: "get",
		// 	success: function (data) {
		// 		console.log("12",data)
		//
		// 	}
		// })
		var xqurl6=HTTP+urls.dataxq6;
		$.ajax({
			headers: {
				authorization: self.Authorization
			},
			contentType: "application/json;charset=utf-8",
			dataType: "json",
			data:{
				id:"1"
			},
			url: xqurl6+row.id,
			type: "get",
			success: function (data) {
				function creatid(id){
					$(id).eq(5).find(".ank_roundnfen").find("span").text(data.totalScore)
					$(id).eq(5).find(".tank_roundscore li").eq(0).find("span").eq(0).text(data.networkLv+"%")
					$(id).eq(5).find(".tank_roundscore li").eq(0).find("span").eq(1).text(data.networkLvScore)
					$(id).eq(5).find(".tank_roundscore li").eq(1).find("span").eq(0).text(data.onlineLv+"%")
					$(id).eq(5).find(".tank_roundscore li").eq(1).find("span").eq(1).text(data.onlineLvScore)
					$(id).eq(5).find(".tank_roundscore li").eq(2).find("span").eq(0).text(data.footprintLv+"%")
					$(id).eq(5).find(".tank_roundscore li").eq(2).find("span").eq(1).text(data.footprintLvScore)
					$(id).eq(5).find(".tank_roundscore li").eq(3).find("span").eq(0).text(data.dataQualifiedLv+"%")
					$(id).eq(5).find(".tank_roundscore li").eq(3).find("span").eq(1).text(data.dataQualifiedLvScore)
					$(id).eq(5).find(".tank_roundscore li").eq(3).find("span").eq(0).text(data.alarmHandleLv+"%")
					$(id).eq(5).find(".tank_roundscore li").eq(3).find("span").eq(1).text(data.alarmHandleLvScore)
					$(id).eq(5).find(".tank_roundscore li").eq(3).find("span").eq(0).text(data.vehicleDriftLv+"%")
					$(id).eq(5).find(".tank_roundscore li").eq(3).find("span").eq(1).text(data.vehicleDriftLvScore)
				}
				creatid(".tank_containner .tank_con")

			}
		})
	},
	operateFormatter:function(index){
		return [
			'<button id="ran_xq" class="ran_xq">详情</button>'+
			'<button id="table_edit" class="ran_xq">修改</button>'+
			'<button id="table_del" class="dele-row">删除</button>'
		].join('');
	},
	ajaxAddcreat:function(){
		var self=this;
		$("#add .primray").click(function(){
			var dataCount=$.map(self.vars.datacreat,function(value,key){
				return key
			});
			$.each(dataCount,function(i,dom){
				self.vars.datacreat[dom]=$("#add ul.add li").eq(i).find("input").val()
			});
			console.log(self.vars.datacreat)
			jrequest.post(urls.addpingtai,self.vars.datacreat).then(res => {
				console.log("23",res)
				$("#check_detail").bootstrapTable('append', res);
				self.ajaxtable()
			})
		})
		$("#add .jdialog-btn .j-btn").eq(0).click(function(){
			$("#addbjcont").hide();
		})
	},
	btnEvent:function(){
		var self=this;
		$(".search-div .j-search-btn button").eq(0).click(function(){
			self.vars.searchTable.platformName=$(".j-search-row .item").eq(0).find("input").val();
			self.vars.searchTable.platformCode=$(".j-search-row .item").eq(1).find("textarea").val();
			self.vars.searchTable.platformCode=$(".j-search-row .item").eq(1).find("textarea").val();
			self.vars.searchTable.page=1;
			self.vars.searchTable.size=10;
			self.ajaxtable(self.vars.searchTable)
		})
		$(".search-div .j-search-btn button").eq(1).click(function(){
			$(".j-search-row .item").eq(0).find("input").val("");
			$(".j-search-row .item").eq(1).find("input").val("");
			self.vars.searchTable.platformName="";
			self.vars.searchTable.platformCode="";
			self.vars.searchTable.page=1;
			self.vars.searchTable.size=10;
			self.ajaxtable(self.vars.searchTable)
		});
		$("#addqueren").click(function(){
			$("#add").show();
			$("#add input[name=zmjm]").click(function(){
				var dataval = $(this).val();
				if(dataval==0){
					$("#add #addCit").show();
				}else{
					$("#add #addCit").hide();
				}
			});
			self.ajaxAddcreat();

		});
		$(".close-div").click(function(){
			$("#gzDialog").hide();
			$("#add").hide();
			$("#addbjcont").hide();
			$("#addbquxiao").hide();
		})
		$("#gzDialog .primray").click(function(){
			$("#gzDialog").hide();
		})
		$(".tank_menu ul li").click(function(){
			var index=$(this).index();
			$(this).addClass("tank_color").siblings("").removeClass("tank_color");
			$(".tank_containner .tank_con").eq(index).show().siblings("").hide();
		});
		var width=$(".tank_con").width();
		var height=$(".tank_con").height();
		$("#tank_round").css({height:height*0.7,width:width*0.2})
		charts.piesScore("tank_round",80)
	},


}

$(function(){
	common.initCatalogueMagePage();
});
